import { defineStore } from "pinia";
import { ref,computed } from "vue";

/* export const useCountStore = defineStore('count', {
    // 动作
    actions:{
        changeSumAndTitle(step:number) {
            this.sum += step
            this.title = 'aaaaaaaaaaa'
            this.desc = '666666666'
        }
    },
    //状态
    state() {
        return {
            sum : 10,
            title: '这是一个测试title',
            desc:'这是内容描述'
        }
    },
    //计算
    getters: {
       bigSum:(state)=>state.sum * 10,
       changeDesc(state):string {
            return state.desc + 'bbbbbbbbbbbbbbb'
       }
    }
}) */
// 组合方式的写法
export const useCountStore = defineStore('count', ()=>{
    // state定义数据
    let sum = ref(10)
    let title = ref('这是一个测试title')
    let desc = ref('这是内容描述')

    // 定义Action
    function changeSumAndTitle(step:number) {
        sum.value += step
        title.value = 'aaaaaaaaaaa'
        desc.value = '666666666'
    }

    const bigSum = computed(()=>{
        return sum.value * 10
    })

    const changeDesc = computed(()=>{
        return desc + 'bbbbbbbbbbbbbbb'
    })

    return {sum, title, desc, changeSumAndTitle, bigSum, changeDesc}
})